// 两个栈实现一个队列
#include"LinkQueue.h"
#include"LinkStack.h"
#include<stdio.h>
#define true 1
#define false 0

struct Queue
{
    LStack stack1;
    LStack stack2;

};

int InitQueue(struct Queue *qp)
{
    InitLinkStack(&qp->stack1);
    InitLinkStack(&qp->stack2);
}

void StackQueuePush(struct Queue *qp,ElementType element)
{
    while(IsEmpty(&qp->stack2)==false)
    {
        Push(&qp->stack1,*Pop(&qp->stack2));
    }
    Push(&qp->stack1,element);
}

ElementType *StackQueuePop(struct Queue *qp)
{
    while(IsEmpty(&qp->stack2)==true)
    {
        while(IsEmpty(&qp->stack1)==false)
        {
            Push(&qp->stack2,*Pop(&qp->stack1));
        }
    }
    return Pop(&qp->stack2);
}

int IsStackQueueEmpty(struct Queue *qp)
{
    if(qp->stack1.stack.len==0 && qp->stack2.stack.len==0)
        return true;
    else
        return false;
}


int main()
{
    struct Queue queue;
    InitQueue(&queue);
    for(int i=0;i<10;i++)
    {
        StackQueuePush(&queue,i+1);
    }
    while(IsStackQueueEmpty(&queue)==false)
    {
        printf("%d ",*StackQueuePop(&queue));
    }
    printf("\n");
    return 0;
}